//
//  GGBaseOrderTableViewCell.m
//  XTXOneToOne
//
//  Created by Canny on 2018/11/15.
//  Copyright © 2018年 WK. All rights reserved.
//

#import "GGBaseOrderTableViewCell.h"



@interface GGBaseOrderTableViewCell ()




@end

@implementation GGBaseOrderTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        [self initView];
    }
    return self;
}

-(void)setLab:(UILabel *)lab withColor:(UIColor *)color andFont:(CGFloat)font andText:(NSString *)text andTextAlignment:(NSTextAlignment)textAlignment{
    lab.text=text;
    lab.textColor=color;
    lab.font=[UIFont systemFontOfSize:font];
    lab.textAlignment=textAlignment;
}


- (void)initView{
    
    self.backgroundColor=[UIColor whiteColor];
    
    /*
     * 做多/做空
     */
    UILabel * lab_order_type = [[UILabel alloc]init];
    [self setLab:lab_order_type withColor:C_green andFont:15 andText:@"" andTextAlignment:NSTextAlignmentLeft];
    [self addSubview:lab_order_type];
    lab_order_type.font = [UIFont boldSystemFontOfSize:15];
    [lab_order_type mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(20));
        make.left.equalTo(self.mas_left).offset(15);
        make.top.equalTo(self.mas_top).offset(10);
    }];
    _lab_order_type=lab_order_type;
    
    /*
     * symbol
     */
    UILabel * lab_symbol = [[UILabel alloc]init];
    [self setLab:lab_symbol withColor:C_black andFont:15 andText:@"加载中..." andTextAlignment:NSTextAlignmentLeft];
    [self addSubview:lab_symbol];
    [lab_symbol mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(20));
        make.left.equalTo(lab_order_type.mas_right).offset(10);
        make.centerY.equalTo(lab_order_type.mas_centerY).offset(0);
        
    }];
    _lab_symbol=lab_symbol;
    
    
    /*
     * //订单状态    @0:待成交；@1:已成交；@2:平仓中;@3:撤销
     */
    UIButton *  btn_status = [[UIButton alloc]init];
    [self addSubview:btn_status];
    [btn_status setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn_status setTitle:@"XX" forState:UIControlStateNormal];
    btn_status.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    btn_status.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    btn_status.backgroundColor=RGB(48, 163, 250);
    [btn_status mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-15);
        make.centerY.equalTo(lab_order_type.mas_centerY).offset(0);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
    }];
    btn_status.layer.cornerRadius = 5;
    btn_status.clipsToBounds=YES;
    _btn_status=btn_status;
    [btn_status addTarget:self action:@selector(statusAction) forControlEvents:UIControlEventTouchUpInside];
    
    
    UILabel * lab1 = [[UILabel alloc]init];
    [self setLab:lab1 withColor:C_gray andFont:12 andText:@"时间" andTextAlignment:NSTextAlignmentLeft];
    [self addSubview:lab1];
    [lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(20));
        make.left.equalTo(self.mas_left).offset(15);
        make.top.equalTo(lab_order_type.mas_bottom).offset(5);
    }];
    
    /*
     * 创建时间戳
     */
    UILabel * lab_create_time = [[UILabel alloc]init];
    [self setLab:lab_create_time withColor:C_gray andFont:12 andText:@"加载中..." andTextAlignment:NSTextAlignmentRight];
    [self addSubview:lab_create_time];
    [lab_create_time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(20));
        make.left.equalTo(self.mas_left).offset(15);
        make.top.equalTo(lab1.mas_bottom).offset(5);
    }];
    _lab_create_time=lab_create_time;
    
    UILabel * lab2 = [[UILabel alloc]init];
    _lab2=lab2;
    [self setLab:lab2 withColor:C_gray andFont:12 andText:@"开仓价" andTextAlignment:NSTextAlignmentCenter];
    [self addSubview:lab2];
    [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(20));
        make.centerX.equalTo(self.mas_centerX).offset(0);
        make.top.equalTo(lab_order_type.mas_bottom).offset(5);
    }];
    
    UILabel * lab_price = [[UILabel alloc]init];
    [self setLab:lab_price withColor:C_gray andFont:12 andText:@"加载中..." andTextAlignment:NSTextAlignmentCenter];
    [self addSubview:lab_price];
    [lab_price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(20));
        make.centerX.equalTo(self.mas_centerX).offset(0);
        make.top.equalTo(lab2.mas_bottom).offset(5);
    }];
    _lab_price=lab_price;
    
    UILabel * lab3 = [[UILabel alloc]init];
    [self setLab:lab3 withColor:C_gray andFont:12 andText:@"开仓数量" andTextAlignment:NSTextAlignmentRight];
    [self addSubview:lab3];
    [lab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(20));
        make.right.equalTo(self.mas_right).offset(-15);
        make.top.equalTo(lab_order_type.mas_bottom).offset(5);
    }];
    _lab3=lab3;
    
    UILabel * lab_amount = [[UILabel alloc]init];
    [self setLab:lab_amount withColor:C_gray andFont:12 andText:@"加载中..." andTextAlignment:NSTextAlignmentRight];
    [self addSubview:lab_amount];
    [lab_amount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(20));
        make.right.equalTo(self.mas_right).offset(-15);
        make.top.equalTo(lab3.mas_bottom).offset(5);
    }];
    _lab_amount=lab_amount;
    
    UILabel * lab4 = [[UILabel alloc]init];
    [self setLab:lab4 withColor:C_gray andFont:12 andText:@"浮动收益" andTextAlignment:NSTextAlignmentRight];
    [self addSubview:lab4];
    [lab4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(20));
        make.left.equalTo(self.mas_left).offset(15);
        make.top.equalTo(lab_create_time.mas_bottom).offset(5);
    }];
    /*
     * ;// 浮动盈亏
     */
    
    UILabel * lab_profit = [[UILabel alloc]init];
    [self setLab:lab_profit withColor:C_gray andFont:12 andText:@"加载中..." andTextAlignment:NSTextAlignmentRight];
    [self addSubview:lab_profit];
    [lab_profit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(20));
        make.left.equalTo(self.mas_left).offset(15);
        make.top.equalTo(lab4.mas_bottom).offset(5);
    }];
    _lab_profit=lab_profit;
    
    UILabel * lab5 = [[UILabel alloc]init];
    [self setLab:lab5 withColor:C_gray andFont:12 andText:@"成交均价" andTextAlignment:NSTextAlignmentCenter];
    [self addSubview:lab5];
    [lab5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(20));
        make.centerX.equalTo(self.mas_centerX).offset(0);
        make.top.equalTo(lab_price.mas_bottom).offset(5);
    }];
    
    UILabel * lab_average_price = [[UILabel alloc]init];
    [self setLab:lab_average_price withColor:C_gray andFont:12 andText:@"加载中..." andTextAlignment:NSTextAlignmentCenter];
    [self addSubview:lab_average_price];
    [lab_average_price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(20));
        make.centerX.equalTo(self.mas_centerX).offset(0);
        make.top.equalTo(lab5.mas_bottom).offset(5);
    }];
    _lab_average_price=lab_average_price;
    
    
    UILabel * lab6 = [[UILabel alloc]init];
    [self setLab:lab6 withColor:C_gray andFont:12 andText:@"成交量" andTextAlignment:NSTextAlignmentRight];
    [self addSubview:lab6];
    [lab6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(20));
        make.right.equalTo(self.mas_right).offset(-15);
        make.top.equalTo(lab_amount.mas_bottom).offset(5);
    }];
    
    
    UILabel * lab_deal = [[UILabel alloc]init];
    [self setLab:lab_deal withColor:C_gray andFont:12 andText:@"加载中..." andTextAlignment:NSTextAlignmentRight];
    [self addSubview:lab_deal];
    [lab_deal mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(20));
        make.right.equalTo(self.mas_right).offset(-15);
        make.top.equalTo(lab6.mas_bottom).offset(5);
    }];
    _lab_deal=lab_deal;
    
    
    
    /*
     * 画线
     */
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:243/255.0 alpha:1];
    [self addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(1));
        make.width.equalTo(@(G_SCREENWIDTH));
        make.left.equalTo(self.mas_left).offset(0);
        make.bottom.equalTo(self.mas_bottom).offset(0);
    }];
    
    
}

-(void)setDataSource:(LTOrderCellModel *)dataSource{
    _dataSource = dataSource;
    NSString *order_type = [NSString stringWithFormat:@"%@",dataSource.order_type];
    //    @1：限价买单；@2：限价卖单；@3：市价买单；@4：市价卖单
    if ([order_type isEqualToString:@"1"]||[order_type isEqualToString:@"3"]) {
        _lab_order_type.text=@"做多";
        _lab_order_type.textColor = C_green;
        
    }else{
        _lab_order_type.text=@"做空";
        _lab_order_type.textColor = C_red;
        
    }
    _lab_symbol.text = [NSString stringWithFormat:@"%@(%@X)",dataSource.symbol,dataSource.lever];
    //    _lab_order_status.text = [NSString stringWithFormat:@"%@",dataSource.order_status];
    _lab_create_time.text = [NSString stringWithFormat:@"%@",dataSource.create_time];
    _lab_price.text = [NSString stringWithFormat:@"%@",dataSource.price];
    _lab_amount.text = [NSString stringWithFormat:@"%@",dataSource.amount];
    _lab_profit.text = [NSString stringWithFormat:@"%@",dataSource.profit];
    _lab_average_price.text = [NSString stringWithFormat:@"%@",dataSource.average_price];
    _lab_deal.text = [NSString stringWithFormat:@"%@",dataSource.deal];
    
}

-(void)statusAction{
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

+(CGFloat)computeHeight:(id)info{
    
    return 150;
}

@end

